package base.chap2;

/**
 * ${DESCRIPTION}
 *
 * @author luoyalan
 * @date 2018/9/11
 */
public class BankAccount {
    private static int LAST_ACCOUNT_NUMBER = 0;

    private String ownerName;
    private int accountNumber;
    private float balance;

    public String getOwnerName() {
        return ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    public int getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(int accountNumber) {
        this.accountNumber = accountNumber;
    }

    public float getBalance() {
        return balance;
    }

    public void setBalance(float balance) {
        this.balance = balance;
    }

    public BankAccount() {
        this("",0,0);
    }

    public BankAccount(String ownerName, int accountNumber, float balance) {
        this.ownerName = ownerName;
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    public float deposit(float amount) {
        balance += amount;
        return balance;
    }

    public float withdraw(float amount) {
        balance -= amount;
        return balance;
    }

    @Override
    public String toString() {
        return "BankAccount{" +
                "ownerName='" + ownerName + '\'' +
                ", accountNumber=" + accountNumber +
                ", balance=" + new java.text.DecimalFormat("$0.00").format(balance) +
                '}';
    }
}
